package com.blog.blog.config;

import com.blog.blog.service.AlertService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 监控定时任务配置
 */
@Slf4j
@Component
@RequiredArgsConstructor
@ConditionalOnProperty(name = "app.monitor.enabled", havingValue = "true", matchIfMissing = true)
public class MonitorScheduleConfig {
    
    private final AlertService alertService;
    
    /**
     * 每5分钟检查一次系统健康状态
     */
    @Scheduled(fixedRate = 300000) // 5分钟
    public void healthCheck() {
        try {
            alertService.checkAndSendHealthAlerts();
        } catch (Exception e) {
            log.error("系统健康检查异常", e);
        }
    }
    
    /**
     * 每小时记录一次系统状态日志
     */
    @Scheduled(cron = "0 0 * * * ?")
    public void logSystemStatus() {
        try {
            log.info("系统状态检查 - 每小时定时任务执行");
            // 这里可以添加更多的系统状态记录逻辑
        } catch (Exception e) {
            log.error("系统状态记录异常", e);
        }
    }
}
